//
//  SJPAppendTableViewCell.m
//  SWS_Project00
//
//  Created by 马继鵬 on 17/3/10.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "SJPAppendTableViewCell.h"

@interface SJPAppendTableViewCell()
@property (weak,nonatomic) UIButton* btn;
@end
@implementation SJPAppendTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self ;
}
#pragma
#pragma-cell布局
- (void)setupUI{
    
    UIButton* btn = [[UIButton alloc]init];
    btn.backgroundColor = kThemeColor;
    [btn setTitle:@"订阅" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"已订阅" forState:UIControlStateSelected];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    btn.titleLabel.font = [UIFont systemFontOfSize:20];
   
    [btn sizeToFit];
    _btn = btn;
    self.accessoryView = btn;
    self.accessoryView.bounds = CGRectMake(0, 0, 100, 44);
    
    [btn addTarget:self action:@selector(selectedClick:) forControlEvents:UIControlEventTouchUpInside];
}
#pragma
#pragma-点击事件
- (void)selectedClick:(UIButton*)sender
{
    sender.selected = !sender.selected;
    if(self.backBlock)
    {
        _backBlock(sender.selected);
    }
}
#pragma
#pragma-赋值
- (void)setModel:(SJPAppendModel *)model
{
    _model = model;
    self.textLabel.text = model.title;
    _btn.selected = model.selectedClick;
}
@end
